#ifndef THREADPOOL_H
#define THREADPOOL_H

#include <stdlib.h>
#include <pthread.h>
#include <cJSON/cJSON.h>
#include <server/transfercall.h>

struct thread_oparg 
{
	//int sock_fd;
	file_ops_st *sock_obj;
	void *arg;
	int (*thread_opt)(file_ops_st *);
};

typedef struct queue
{
	struct thread_oparg data;
	struct queue *next, *prev;
}queue_st,*queue_p;

typedef struct 
{
	int tp_num;
	pthread_t *tp_tid;
	void *(*tp_func)(void *);
	void *tp_arg;
	queue_p tp_pq;
	pthread_mutex_t tp_mutex;
	pthread_cond_t tp_cond;
}threadpool_st,*threadpool_p;


threadpool_p init_thread_pool(int thread_num, void *(*thread_func)(void *), void *args);

void run_thread_pool(threadpool_p tp);
void destory_thread_pool(threadpool_p tp);
void addThreadPool(threadpool_p tp, struct thread_oparg data);
void getThreadPool(threadpool_p tp, struct thread_oparg *data);
#endif
